package com.dwy2002.order.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dwy2002.common.utils.JwtUtil;
import com.dwy2002.order.mapper.OrderStatusLogsMapper;
import com.dwy2002.order.service.IOrderStatusLogsService;
import com.dwy2002.pojo.dto.order.OrderStatusLogsDTO;
import com.dwy2002.pojo.po.order.OrderStatusLogs;
import com.dwy2002.pojo.po.users.Users;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import static com.dwy2002.common.utils.Utils.getToken;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/06
 */
@Service
@RequiredArgsConstructor
public class OrderStatusLogsServiceImpl extends ServiceImpl<OrderStatusLogsMapper, OrderStatusLogs> implements IOrderStatusLogsService {
    private final JwtUtil jwtUtil;

    /**
     * 记录订单状态变化
     *
     * @param dto 订单状态变更日志表实体类DTO
     * @author 杜伟毅
     * @since 2025/3/15 0015 14:35
     */
    @Override
    public void recordOrderStatusLog(OrderStatusLogsDTO dto) {
        OrderStatusLogs orderStatusLogs = BeanUtil.copyProperties(dto, OrderStatusLogs.class);
        orderStatusLogs.setOperatorId(jwtUtil.parseToken(getToken(), Users.class).getId());
        save(orderStatusLogs);
    }
}
